package com.br.aiops.alert.config.db;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ReceiverGroupUsersRepository extends JpaRepository<ReceiverGroupUsersDTO, Long> {

    /**
     * 查找所有组员
     * 注：通过使用联合主键方式进行查询
     * @return
     */
    @Query(nativeQuery = true, value = "SELECT concat(rg.id, '_', l.id) id, rg.rule_id, rg.group_id, l.cas_id, l.phone, l.email, l.owner\n" +
            "FROM log_alert_receiver_rules_group rg LEFT JOIN\n" +
            "log_alert_receiver_group_users l\n" +
            "ON rg.group_id = l.group_id\n")
    List<ReceiverGroupUsersDTO> findAll();
}
